package com.wwj.springcloud.hystrix;

import com.wwj.springcloud.entity.Dept;
import com.wwj.springcloud.feign.DeptClientServiceFeign;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.ArrayList;
import java.util.List;

// 服务降级
@Component
public class DeptClientServiceHystrix implements FallbackFactory<DeptClientServiceFeign> {
    @Override
    public DeptClientServiceFeign create(Throwable throwable) {
        return new DeptClientServiceFeign() {
            @Override
            public boolean addDeptFeign(Dept dept) {
                return false;
            }

            @Override
            public Dept queryByIdFeign(@PathVariable("id") Long id) {
                Dept dept = new Dept();
                dept.setDeptNo(id);
                dept.setName("服务降级，该服务已关闭");
                dept.setDbName("没数据");
                return dept;
            }

            @Override
            public List<Dept> queryAllFeign() {
                return new ArrayList<Dept>();
            }
        };
    }
}
